fix(coop): host re-validate craft capacity in SHARED (#121) - #123
Merged
Conversation
In SHARED either player can edit any craft, so the client-side capacity gate is not enough: a stale-view request that passes the initiator's gate reached the host, which applied it without re-checking -> an over-capacity craft that can desync or fault a later deployment. - Factor CraftWeaponsState's four inline capacity checks into a pure static equipCapacityError() (byte-identical math) and call it from both lstWeaponsClick and craftRearmValidate. - soldierArmorValidate now re-runs Craft::validateArmorChange host-side, mirroring SoldierArmorState::lstArmorClick. Harness fidelity: harnessEquip/harnessSetArmor now run the client gate (surfaced as resp["gate"]); a new `force` param bypasses it to model a stale replica whose gate passed. New regression test test_shared_capacity_host_gate.py drives an over-capacity craft_rearm / soldier_armor from a replica with force and asserts the host REJECTS it (shared_fail reason) with both worlds left unchanged and equal. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #121.
Problem
In SHARED co-op either player can command/edit any craft, so the client-side capacity gate is not enough. A stale-view concurrent edit passes the initiator's gate, reaches the host, and pre-fix the host applied it without re-checking craft capacity — producing an over-capacity craft that can cause a coop desync or a battlescape/deployment fault.
Two host validators were missing the re-check:
craftRearmValidatevalidated base/craft/slot/weapon-slot only — none of the fourCraftWeaponsStatecapacity gates (cargo / HWP / storage-items / storage-space).soldierArmorValidatevalidated base/soldier/armor existence only — notCraft::validateArmorChange(STR_NOT_ENOUGH_CRAFT_SPACE).Fix
CraftWeaponsState::lstWeaponsClickinto a purestatic CraftWeaponsState::equipCapacityError(...)(math is byte-identical to the old block, so host and client can never disagree), and call it from both the UI andcraftRearmValidate.soldierArmorValidatenow re-runsCraft::validateArmorChangehost-side, mirroringSoldierArmorState::lstArmorClick.Both validators funnel host-origin and replica-origin commands through
processHostCmd, so the gate now protects every path; a rejected request emitsshared_failand mutates nothing.Harness fidelity + regression test
harnessEquip/harnessSetArmornow run the client gate (surfaced asresp["gate"]), matching a real player's screen. A newforceparam bypasses it to model a stale replica whose gate passed.tools/coop_test/test_shared_capacity_host_gate.py(throwaway mod: an over-capacity craft weapon + a zero-large-capacity Skyranger + a size-2 armor) checks each gate twice:STR_NOT_ENOUGH_CARGO_SPACE/STR_NOT_ENOUGH_CRAFT_SPACE) and both worlds stay unchanged and equal.Testing
python tools/coop_test/test_shared_capacity_host_gate.py— both sections green.python tools/coop_test/test_shared_equip2.py— all three sections green (no regression from the harness signature change).🤖 Generated with Claude Code